package sve;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Stack;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Set;

import xadd.XADD;

public class Utils {

	public static void print(Set s) {
		print(System.out, s);
	}

	public static void print(PrintStream out, Set s) {
		for (Object o : s) {
			out.println(o.toString());
		}
	}

	public static void print(List s) {
		print(System.out, s);
	}

	public static void print(PrintStream out, List s) {
		for (Object o : s) {
			out.println(o.toString());
		}
	}

	public static boolean contains(String v, String[] q) {
		for (String s : q) {
			if (s.equals(v)) {
				return true;
			}
		}
		return false;
	}

	public static boolean contains(String v, Set s) {
		return s.contains(v);
	}

	public static boolean contains(String v, ArrayList o) {
		return o.contains(v);
	}

	public static boolean isInStack(Set cv, Stack s) {
		for (Object item : cv) {
			if (!s.contains(item)) {
				return false;
			}
		}

		return true;
	}

	public static int indexOf(String[] args, String key) {
		int idx = -1;
		for (int i = 0; i < args.length; i++) {
			if (args[idx].equalsIgnoreCase(key)) {
				idx = i;
				break;
			}
		}
		return idx;
	}

	public static void print(String filePath, String str) {
		try {
			print(new PrintStream(filePath), str);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static void print(PrintStream ps, String str) {
		ps.print(str);
	}

	public static void print(String msg, Pair<Integer, XADD> p) {
		print(msg, p.getKey(), p.getValue());
	}

	public static void print(String msg, int id, XADD x) {
		print(System.out, msg, id, x);
	}

	public static void print(PrintStream out, String msg, int id, XADD x) {
		out.println(" ++++++++++++++++++++++++++++++ ");
		out.println(msg);
		out.println(x.getString(id, false));
		out.println(" ++++++++++++++++++++++++++++++ ");
	}

	public static void print(String path, String msg, Pair<Integer, XADD> p) {
		print(path, msg, p.getKey(), p.getValue());
	}

	public static void print(String path, String msg, int id, XADD x) {
		try {
			print(new PrintStream(path), msg, id, x);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static void addAll(Collection list1, Collection list2) {
		for (Object o : list2) {
			if (!list1.contains(o)) {
				list1.add(o);
			}
		}
	}

	public static void removeIntersection(Collection hs, Collection list) {
		for (Object o : list) {
			if (hs.contains(o)) {
				hs.remove(o);
			}
		}
	}
}
